package com.cloud.adrian.novel.search.manager.mq;

import com.cloud.adrian.novel.common.constant.AmqpConstants;
import com.cloud.adrian.novel.search.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听mq消息，并做出处理
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/06/03
 */
@Component
@RequiredArgsConstructor
public class MqListenerManager {
    private final SearchService searchService;

    @RabbitListener(queues = AmqpConstants.BookChange.INSERT_QUEUE)
    public void listenNovelInsert(Long bookId) throws IOException {
        searchService.insertNovel(bookId);
    }

    @RabbitListener(queues = AmqpConstants.BookChange.UPDATE_QUEUE)
    public void listenNovelUpdate(Long bookId) throws IOException {
        searchService.updateNovel(bookId);
    }

    @RabbitListener(queues = AmqpConstants.BookChange.DELETE_QUEUE)
    public void listenNovelDelete(Long bookId) throws IOException {
        searchService.deleteNovel(bookId);
    }

}
